import request from "@/utils/request"
import {AxiosPromise} from "axios";
import {QuizForm, QuizQuery, TagVO} from "./types";
import {Result, TableDataInfo} from "@/model";

/**
 * 查看题目列表
 * @param params 查询条件
 * @returns 题目列表
 */
export function getQuizList(params: QuizQuery): AxiosPromise<TableDataInfo> {
    return request({
        url: "/admin/quiz/list",
        method: "get",
        params,
    });
}

/**
 * 获取所有标签选项
 * @returns 标签选项
 */
export function getTagOption(): AxiosPromise<Result<TagVO[]>> {
    return request({
        url: "/admin/tag/option",
        method: "get"
    });
}

/**
 * 获取题目标签选项
 * @returns 标签选项
 */
export function getQTagOption(): AxiosPromise<Result<TagVO[]>> {
    return request({
        url: "/admin/qtag/option",
        method: "get"
    });
}

/**
* 添加题目
* @param data 题目信息
*/
export function addQuiz(data: QuizForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/quiz/add",
        method: "post",
        data
    });
}

/**
 * 删除题目
 * @param data 题目id
 */
export function deleteQuiz(data: number[]): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/quiz/delete",
        method: "delete",
        data,
    });
}

/**
 * 修改题目
 * @param data 题目信息
 */
export function updateQuiz(data: QuizForm): AxiosPromise<Result<null>> {
    return request({
        url: "/admin/quiz/update",
        method: "put",
        data,
    });
}

/**
 * 编辑题目
 * @param quizId 题目id
 */
export function editQuiz(quizId: number): AxiosPromise<Result<QuizForm>> {
    return request({
        url: `/admin/quiz/edit/${quizId}`,
        method: "get",
    });
}